package com.atguigu.servlet;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.FileOutputStream;
import java.io.IOException;
@WebServlet("/servlet3")
public class Servlet3 extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ServletContext servletContext = getServletContext();

        //向upload目录写入一个文件
        //获得某个指向项目部署位置下的某个文件目录下的磁盘真实路径的api
        String path = servletContext.getRealPath("upload");
        System.out.println(path);
      /*  FileOutputStream fos=new FileOutputStream(path+"/a.txt");*/
        //获得项目部署的上下文名称，项目的访问路径（名称）
        //后续我们会学习在项目中使用相对路径和绝对路径去找目标资源

        //获得项目的上下文路径，项目的访问路径
        String contextPath = servletContext.getContextPath();
        System.out.println(contextPath);

    }
}
